﻿using Dapper;
using MyPLC.Entity;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace MyPLC
{
    public partial class Dapper
    {        
        /// <summary>
        /// 获取Mysql的订单表,首页从0开始
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public tbl_set GetSetInfo(string ipAddress)
        {
            using (IDbConnection connection = GetSqlConnection())
            {
                string sql = @" select * from tbl_set where IPAddress=@IPAddress ; ";
                return connection.QueryFirstOrDefault<tbl_set>(sql,new { IPAddress = ipAddress });
            }
        }
        /// <summary>
        /// 更新设置
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public bool UpdateSet(tbl_set model)
        {
            tbl_set set = GetSetInfo(model.IPAddress);
            using (IDbConnection connection = GetSqlConnection())
            {
                string sql = string.Empty;
                if (set != null)
                {
                    sql = @" update tbl_set set WDPL=@WDPL,ZDYLPL=@ZDYLPL,DCLPL=@DCLPL where IPAddress=@IPAddress ;";
                }
                else
                {
                    sql = @" insert into tbl_set (WDPL,ZDYLPL,DCLPL,IPAddress,CREATEDATE) values (@WDPL,@ZDYLPL,@DCLPL,@IPAddress,@CREATEDATE) ;";
                }
                return connection.Execute(sql, model, null, null, CommandType.Text) > 0;
            }
        }
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CreateOrder(tbl_order model)
        {
            using (IDbConnection connection = GetSqlConnection())
            {
                string sql = @" insert into tbl_order (D1082,D3013,D3014,D3016,D3017,D3019,D3020,D3022,D3023,D3000,D1077,D1370,D3122,D1009,D1029,D1030,D1535,D1031,D1032,D1033,D1034,D1035,D1036,D1037,D1038,D1039,D1000,D1001,D1002,D1003,D1005,D1006,D1380,D3142,D3141,D3140,D3145,D3461,CREATEDATE,IPAddress) 
                                                        values (@D1082,@D3013,@D3014,@D3016,@D3017,@D3019,@D3020,@D3022,@D3023,@D3000,@D1077,@D1370,@D3122,@D1009,@D1029,@D1030,@D1535,@D1031,@D1032,@D1033,@D1034,@D1035,@D1036,@D1037,@D1038,@D1039,@D1000,@D1001,@D1002,@D1003,@D1005,@D1006,@D1380,@D3142,@D3141,@D3140,@D3145,@D3461,@CREATEDATE,@IPAddress) ;";
                return connection.Execute(sql, model, null, null, CommandType.Text) > 0;
            }
        }
        /// <summary>
        /// 写入温度数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CreateSignalOrder(tbl_signalorder model)
        {
            using (IDbConnection connection = GetSqlConnection())
            {
                string sql = @" insert into tbl_signalorder (D1029,D1030,D1031,D1032,D1033,D1034,D1035,D1036,D1037,D1038,D1039,D1535,D1370,CREATEDATE,IPAddress) 
                                                        values (@D1029,@D1030,@D1031,@D1032,@D1033,@D1034,@D1035,@D1036,@D1037,@D1038,@D1039,@D1535,@D1370,@CREATEDATE,@IPAddress) ;";
                return connection.Execute(sql, model, null, null, CommandType.Text) > 0;
            }
        }
        /// <summary>
        /// 写入振动压力数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CreateZDYLOrder(tbl_zdylorder model)
        {
            using (IDbConnection connection = GetSqlConnection())
            {
                string sql = @" insert into tbl_zdylorder (D3018,D3021,D3012,D3015,D3031,D3032,D3029,D3030,D1370,CREATEDATE,IPAddress) 
                                                        values (@D3018,@D3021,@D3012,@D3015,@D3031,@D3032,@D3029,@D3030,@D1370,@CREATEDATE,@IPAddress) ;";
                return connection.Execute(sql, model, null, null, CommandType.Text) > 0;
            }
        }
        /// <summary>
        /// 写入电磁流数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CreateRealOrder(tbl_realorder model)
        {
            using (IDbConnection connection = GetSqlConnection())
            {
                string sql = @" insert into tbl_realorder (D1000,D1001,D1002,D1003,D1004,D1005,D1006,D1007,D1370,CREATEDATE,IPAddress) 
                                                        values (@D1000,@D1001,@D1002,@D1003,@D1004,@D1005,@D1006,@D1007,@D1370,@CREATEDATE,@IPAddress) ;";
                return connection.Execute(sql, model, null, null, CommandType.Text) > 0;
            }
        }

    }
}
